/**
 * Created by vincent on 2016/12/22.
 */
Array.prototype.addArray = function (array) {
    for (var i = 0; i < array.length; i++) {
        this.push(array[i]);
    }
};
// 乱序
Array.prototype.shuffle = function () {
    for (var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x) ;
    return this;
};

Array.prototype.remove = function (index) {
    if (isNaN(index) || index > this.length) {
        return false;
    }
    this.splice(index, 1);
};

Array.prototype.removeForUid = function (obj) {
    for (var i = 0; i < this.length; i++) {
        if (this[i].uid == obj.uid) {
            this.remove(i);
            return;
        }
    }
};

Array.isNotEmpty = function (array) {
    return !!(array != null && array != undefined && array.length > 0);
};

Array.forEach = function (array, fn) {
    if (Array.isArray(array)) {
        for (var i = 0; i < array.length; i++) {
            var rv = fn(array[i], i);
            if (rv != undefined) {
                return rv;
            }
        }
    }
};

Array.isArray = function (obj) {
    return Object.prototype.toString.call(obj) === '[object Array]';
};
